#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;

int Getmonthday(int year, int month)
{
    static int arr[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
    if ((month == 2) &&
        (year % 4 == 0 && year % 100 != 0)
        || (year % 400 == 0))
        return 29;
    return arr[month - 1];
}
int main() {
    int a = 0;
    int arr[13] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
    cin >> a;
    
    int* year = new int[a];
    int* month = new int[a];
    int* day = new int[a];
    int* n = new int[a];
    for (int i = 0; i < a; i++)
    {
        cin >> year[i] >> month[i] >> day[i] >> n[i];

    }

    for (int i = 0; i < a; i++)
    {
        day[i] += n[i];
        while (day[i] > Getmonthday(year[i],month[i])) {
            day[i] = day[i] - Getmonthday(year[i], month[i]);
            /*if ((month[i] == 2) && (year[i] % 4 == 0 && year[i] % 100 != 0) || (year[i] % 400 == 0))
                day[i]--;*/

            month[i]++;
            if (month[i] == 13)
            {
                month[i] = 1;;
                year[i]++;
            }
        }
        //cout<<year<<"-"<<month<<"-"<<day<<endl;
        printf("%d-%.2d-%.2d\n", year[i], month[i], day[i]);
    }
    delete[] year;
    delete[] month;
    delete[] day;
    delete[] n;

    return 0;
}